<script setup lang="ts">
import { getBarcodeDetailAPI } from '@/api/code'
import type { KpcodeBarcodeScanEntity } from '@/types/member'
import { onLoad } from '@dcloudio/uni-app'
import { onMounted, ref } from 'vue'

const query = defineProps<{
  id: string
  type: number
}>()

const detail = ref<KpcodeBarcodeScanEntity>({
  kpcodeJackWinningEntity:{}
})
const getBarcodeDetail = async () => {
  if (query.id) {
    const res = await getBarcodeDetailAPI(query.id)
    detail.value = res.data
  }
}

onMounted(() => {
  const title = query.type == 1 ? '扫码详情' : '抽奖详情'
  uni.setNavigationBarTitle({
    title: title,
  })
})

onLoad(() => {
  getBarcodeDetail()
})

const prizeCash = () => {
  if (detail.value.kpcodeJackWinningEntity.status == '1') {
    uni.navigateTo({url:`/pages/prizeCash/prizeCash?id=${query.id}`})
  }
  if (detail.value.kpcodeJackWinningEntity.status == '2') {
    uni.showToast({ icon: 'none', title: '你的兑奖审核已提交' })
  }
  if (detail.value.kpcodeJackWinningEntity.status == '3') {
    uni.showToast({ icon: 'none', title: '你的奖已过期' })
  }
  if (detail.value.kpcodeJackWinningEntity.status == '4') {
    uni.showToast({ icon: 'none', title: '你的奖已作废' })
  }
  if (detail.value.kpcodeJackWinningEntity.status == '5') {
    uni.showToast({ icon: 'none', title: '你已经完成了兑奖' })
  }
}
</script>

<template>
  <view class="order_status" v-if="detail">
    <view class="status fail" v-if="detail.status == '4'">
      <uni-icons type="checkbox" color="#fff" size="50" />
      <text class="status_text">等待开奖！</text>
    </view>
    <view class="status fail" v-if="detail.status == '5'">
      <uni-icons type="checkbox" color="#fff" size="50" />
      <text class="status_text">很遗憾，未中奖！</text>
    </view>
    <view class="status success" v-if="detail.status == '6'">
      <uni-icons type="checkbox" color="#fff" size="50" />
      <text class="status_text">恭喜你，扫码抽奖成功</text>
    </view>
    <view class="status fail" v-if="detail.status == '7'">
      <uni-icons type="checkbox" color="#fff" size="50" />
      <text class="status_text">已过期！</text>
    </view>
  </view>
  <view class="form">
    <view class="form-content">
      <view class="form-item image_upload">
        <text class="label">发码商</text>
        <text class="info">{{ detail.actBusName }}</text>
      </view>
      <view class="form-item image_upload">
        <text class="label">承销商</text>
        <text class="info">{{ detail.bindBusName }}</text>
      </view>
      <view class="form-item image_upload">
        <text class="label">承销商地址</text>
        <text class="info">{{ detail.bindBusAddress }}</text>
      </view>
      <view class="form-item">
        <text class="label">乐促码编号</text>
        <text class="info">{{ detail.scanCode }}</text>
      </view>
      <view class="form-item">
        <text class="label">扫码时间</text>
        <text class="info">{{ detail.scannedTime }}</text>
      </view>
      <view class="form-item">
        <text class="label">期号</text>
        <text class="info">{{ detail.jack ? detail.jack.jackPeriod : '暂无' }}</text>
      </view>
      <view class="form-item">
        <text class="label">开奖时间</text>
        <text class="info">{{ detail.jack ? detail.jack.jackStartTime : '暂无'}}</text>
      </view>
      <view class="form-item" v-if="detail.status == '6'">
        <text class="label">中奖等级</text>
        <text class="info">{{
          detail.kpcodeJackWinningEntity ? detail.kpcodeJackWinningEntity.jackGrade : '暂无'
        }}</text>
      </view>
      <view class="form-item" v-if="detail.status == '6'">
        <text class="label">奖项金额</text>
        <text class="info"
          >{{
            detail.kpcodeJackWinningEntity ? detail.kpcodeJackWinningEntity.jackPrice : '暂无'
          }}
          元</text
        >
      </view>
      <view class="form-item" v-if="detail.status == '6'">
        <text class="label">税金</text>
        <text class="info">{{ detail.kpcodeJackWinningEntity.taxation ? detail.kpcodeJackWinningEntity.taxation : '0' }} 元</text>
      </view>
      <view class="form-item" v-if="detail.status == '6'">
        <text class="label">到账金额</text>
        <text class="info">{{ detail.kpcodeJackWinningEntity.winningPrice ? detail.kpcodeJackWinningEntity.winningPrice : '0' }} 元</text>
      </view>
      <view class="form-item">
        <text class="label">乐促码状态</text>
        <view class="info"
          ><view class="tag">{{ detail.status == '4'?'待开奖':detail.status == '5'?'未中奖':detail.status == '6'?'已中奖':'已过期' }}</view></view
        >
      </view>
    </view>
    <!-- 提交按钮 -->
    <button class="form-button" @tap="prizeCash" v-if="detail.status == '1'">兑奖</button>
  </view>
</template>

<style lang="scss">
.status {
  background-color: #27ba9b;
  padding: 30rpx;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  .status_text {
    color: #fff;
    margin-top: 20rpx;
    font-size: 26rpx;
    line-height: 50rpx;
    text-align: center;
  }
}
// 表单
.form {
  background-color: #f4f4f4;
  padding-top: 10rpx;
  padding-bottom: 60rpx;

  &-content {
    margin: 20rpx 20rpx 0;
    padding: 0 20rpx;
    border-radius: 10rpx;
    background-color: #fff;
  }

  &-item {
    display: flex;
    height: 96rpx;
    line-height: 46rpx;
    padding: 25rpx 10rpx;
    background-color: #fff;
    font-size: 28rpx;
    border-bottom: 1rpx solid #ddd;

    &:last-child {
      border: none;
    }

    .label {
      width: 180rpx;
      color: #333;
    }
    .tag {
      color: #27ba9b;
    }
  }
  .image_upload {
    height: auto;
  }
  &-button {
    height: 80rpx;
    text-align: center;
    line-height: 80rpx;
    margin: 30rpx 20rpx;
    color: #fff;
    border-radius: 80rpx;
    font-size: 30rpx;
    background-color: #27ba9b;
  }
}
</style>
